/*
 * RoomReport.java
 *
 * Created on April 29, 2006, 8:03 AM
 */

package phs_project;
import com.toedter.calendar.JDateChooser;
import java.util.Vector;
import javax.swing.*;
import java.text.SimpleDateFormat;
/**
 *
 * @author  TUNG
 */
public class RoomReport extends javax.swing.JDialog {
    
    /** Creates new form RoomReport */
    public RoomReport(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        addDataToCombo();
        
        
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtbegindate = new com.toedter.calendar.JDateChooser();
        jLabel2 = new javax.swing.JLabel();
        txtenddate = new com.toedter.calendar.JDateChooser();
        jLabel3 = new javax.swing.JLabel();
        cbxloaiphong = new javax.swing.JComboBox();
        jButton2 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbldsphong = new javax.swing.JTable();
        jPanel3 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        txttongsoluot = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        txttongtienphong = new javax.swing.JFormattedTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        txtmaxloaiphong = new javax.swing.JTextField();
        txtmaxroom = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        txtminloaiphong = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        txtminroom = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("B\u00e1o c\u00e1o theo ph\u00f2ng");
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "T\u00f9y ch\u1ecdn"));
        jLabel1.setText("T\u1eeb ng\u00e0y");

        txtbegindate.setDateFormatString("MM,dd, yyyy");

        jLabel2.setText("\u0110\u1ebfn ng\u00e0y");

        txtenddate.setDateFormatString("MM,dd, yyyy");

        jLabel3.setText("Lo\u1ea1i ph\u00f2ng");

        jButton2.setText("Xem b\u00e1o c\u00e1o");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel1Layout.createSequentialGroup()
                        .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .add(jLabel1)
                        .add(30, 30, 30))
                    .add(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jLabel2)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED))
                    .add(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jLabel3)))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(txtenddate, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE)
                    .add(cbxloaiphong, 0, 143, Short.MAX_VALUE)
                    .add(jButton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 116, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, txtbegindate, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel1)
                    .add(txtbegindate, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(25, 25, 25)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel2)
                    .add(txtenddate, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(25, 25, 25)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel3)
                    .add(cbxloaiphong, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(13, 13, 13)
                .add(jButton2)
                .addContainerGap())
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Danh s\u00e1ch c\u00e1c ph\u00f2ng"));
        tbldsphong.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(tbldsphong);

        org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 378, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 148, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Th\u1ed1ng k\u00ea"));
        jLabel5.setText("T\u1ed5ng s\u1ed1 l\u01b0\u1ee3t ph\u00f2ng \u0111\u01b0\u1ee3c thu\u00ea");

        txttongsoluot.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 11));
        txttongsoluot.setEnabled(false);

        jLabel6.setText("T\u1ed5ng ti\u1ec1n ph\u00f2ng");

        txttongtienphong.setFont(new java.awt.Font("SansSerif", 1, 12));

        jLabel7.setText("Lo\u1ea1i ph\u00f2ng \u0111\u01b0\u1ee3c thu\u00ea nhi\u1ec1u nh\u1ea5t");

        jLabel8.setText("Ph\u00f2ng \u0111\u01b0\u1ee3c thu\u00ea nhi\u1ec1u nh\u1ea5t");

        jLabel9.setText("Lo\u1ea1i ph\u00f2ng \u0111\u01b0\u1ee3c thu\u00ea \u00edt nh\u1ea5t");

        jLabel10.setText("Ph\u00f2ng \u0111\u01b0\u1ee3c thu\u00ea \u00edt nh\u1ea5t");

        org.jdesktop.layout.GroupLayout jPanel3Layout = new org.jdesktop.layout.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel7)
                    .add(jLabel5)
                    .add(jLabel8))
                .add(11, 11, 11)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(txtmaxroom)
                    .add(txtmaxloaiphong, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 95, Short.MAX_VALUE)
                    .add(txttongsoluot, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 142, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(19, 19, 19)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel9)
                    .add(jLabel6, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 98, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel10))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(txtminroom, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 137, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, txtminloaiphong, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 137, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, txttongtienphong, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 137, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createSequentialGroup()
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel5)
                    .add(txttongtienphong, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel6)
                    .add(txttongsoluot, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel7)
                    .add(txtmaxloaiphong, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(txtminloaiphong, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel9))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel8)
                    .add(txtmaxroom, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel10)
                    .add(txtminroom, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(25, 25, 25))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jButton1.setText("Tho\u00e1t");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel4Layout = new org.jdesktop.layout.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap(298, Short.MAX_VALUE)
                .add(jButton1)
                .add(278, 278, 278))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .add(jButton1)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(layout.createSequentialGroup()
                        .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 102, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO add your handling code here:
        listRoom();
        thongkeloaiphong();
    }//GEN-LAST:event_jButton2ActionPerformed
        
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_jButton1ActionPerformed
    private void addDataToCombo(){
        String sql = "select name from roomstype";
        new publicClass().addItemTooCombobox(cbxloaiphong,sql,"Tất cả các loại");
    }   
    
    private void listRoom(){
        sdf = new SimpleDateFormat("MM/dd/yyyy");
        bdate = sdf.format(txtbegindate.getDate());
        System.out.println(bdate); 
        eDate = sdf.format(txtenddate.getDate());   
        System.out.println(eDate); 
        room_type = cbxloaiphong.getSelectedItem().toString();
        if(room_type == "Tất cả các loại"){
            String sql = "select * from room_type_report where begindate between '" + bdate + "' and '" + eDate + "'" ;
            System.out.println(sql);
            new publicClass().addItemToTable(tbldsphong,sql);
        }
        else{
            String sql = "select * from room_type_report where name = N'" + room_type + "' AND begindate between '" + bdate + "' and '" + eDate + "'" ;
            System.out.println(sql);
            new publicClass().addItemToTable(tbldsphong,sql);
        }
        
    }
    private void thongkeloaiphong(){
        sdf = new SimpleDateFormat("MM/dd/yyyy");
        bdate = sdf.format(txtbegindate.getDate());
        System.out.println(bdate); 
        eDate = sdf.format(txtenddate.getDate());   
        System.out.println(eDate); 
        room_type = cbxloaiphong.getSelectedItem().toString();
        if(room_type == "Tất cả các loại"){
            String sql = "select count(*) as dem  from room_type_report where begindate between '" + bdate + "' and '" + eDate + "'" ;
            String countORder = new publicClass().selectDateToString(sql,"dem");
            txttongsoluot.setText(countORder);
            //tinh tong tien
            String sqltt = "select sum(od_total) as demtien  from room_type_report where begindate between '" + bdate + "' and '" + eDate + "'" ;
            float countTotal = new publicClass().selectDataToFloat(sqltt,"demtien");
            txttongtienphong.setValue(new Float(countTotal));
            //thong ke loai phong duoc thue
            String  strsql = "select top 1 name,count(name) as dem from room_type_report where begindate between '" + bdate + "' and '" + eDate + "' group by name order by dem DESC";
            String loai_phong_thue_nhieu_nhat = new publicClass().selectDateToString(strsql,"name");
            txtmaxloaiphong.setText(loai_phong_thue_nhieu_nhat);
            
            String strsql1 = "select top 1 name,count(name) as dem from room_type_report where begindate between '" + bdate + "' and '" + eDate + "' group by name order by dem ASC";
            String loai_phong_thue_it_nhat = new publicClass().selectDateToString(strsql1,"name");
            txtminloaiphong.setText(loai_phong_thue_it_nhat);
            
            //thong ke phong duoc thue nhieu nhat
            String strphong = "";
            strphong = strphong + "select top 5 roomNumb,count(roomNumb) as dem from room_type_report where begindate between '" + bdate + "' and '" + eDate + "' group by roomNumb"; 
            strphong = strphong + " having count(roomNumb) > 2 order by dem DESC" ;
            Vector phong_thue_nhieu_nhat = new Vector();
            phong_thue_nhieu_nhat = new publicClass().getDataToVector(strphong,"roomNumb");
            String result = "";
            for(int i = 0;i<phong_thue_nhieu_nhat.size()-2;i++){
                result = result + phong_thue_nhieu_nhat.get(i).toString() + ", ";
            }
            result = result + phong_thue_nhieu_nhat.get(phong_thue_nhieu_nhat.size()-1).toString();
            txtmaxroom.setText(result);                                  
        }
        else{
            String sql = "select count(*) as dem  from room_type_report where name = N'" + room_type + " and begindate between '" + bdate + "' and '" + eDate + "'" ;
            String countORder = new publicClass().selectDateToString(sql,"dem");
            txttongsoluot.setText(countORder);
            //tinh tong tien
            String sqltt = "select sum(od_total) as demtien  from room_type_report where name = N'" + room_type + " and begindate between '" + bdate + "' and '" + eDate + "'" ;
            float countTotal = new publicClass().selectDataToFloat(sqltt,"demtien");
            txttongtienphong.setValue(new Float(countTotal));
           
        }
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new RoomReport(new javax.swing.JFrame(), true).setVisible(true);
            }
        });
    }
    private String bdate,eDate,room_type;
    private SimpleDateFormat sdf;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cbxloaiphong;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tbldsphong;
    private com.toedter.calendar.JDateChooser txtbegindate;
    private com.toedter.calendar.JDateChooser txtenddate;
    private javax.swing.JTextField txtmaxloaiphong;
    private javax.swing.JTextField txtmaxroom;
    private javax.swing.JTextField txtminloaiphong;
    private javax.swing.JTextField txtminroom;
    private javax.swing.JTextField txttongsoluot;
    private javax.swing.JFormattedTextField txttongtienphong;
    // End of variables declaration//GEN-END:variables
    
}
